package com.kamistoat.meimeichat.meimeichatserverapplication.netty.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 用于定义一些Netty Server 会用到的Bean
 */
@Configuration
public class NettyBeanInitializer {

    /**
     * Netty Server 的异步线程池
     * @return
     */
    @Bean(name = "nettyThreadPoolExecutor")
    public ThreadPoolExecutor nettyThreadPoolExecutor(){
        return new ThreadPoolExecutor(
                25,
                200,
                10,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(50000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
